/**
 * 
 */
package com.example.rabbitmqTest;

import org.assertj.core.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;  
  
/** 
 * rabbit-mq测试controller 
 * Created by zhonglinsen on 2017/11/30. 
 */  
@Controller
@RequestMapping("/mq")
public class MqController {  
  
    private static final Logger log= LoggerFactory.getLogger(MqController.class);  
  
    private static final String prex="mq";  
  
    @Autowired  
    private Environment env;  
  
    @Autowired  
    private AmqpTemplate rabbitTemplate;  
  
    @RequestMapping(value = "/send",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)  
    @ResponseBody  
    public String sendAndRec(String message) throws Exception{  
    	System.out.println(123123);
        if (Strings.isNullOrEmpty(message)){  
            message=env.getProperty("mq.first.message");  
        }  
        log.debug("发送消息： {} ",message);  
        rabbitTemplate.convertAndSend(env.getProperty("mq.first.queue"),message);  
        return "123";  
    }  
  
}  
